﻿using Microsoft.SqlServer.Management.Smo;

namespace Bewise.SmartIndexManager.Core.Classes.Operations
{
    public static class IndexManagerOperations
    {
        static readonly RebuildOperation RebuildOperation = new RebuildOperation();
        static readonly ReorganizeOperation ReorganizeOperation = new ReorganizeOperation();

        public static int IndexFillFactorSeuil { get; set; }

        public static AbstractOperation Create(Index index)
        {
            if (index.FillFactor < IndexFillFactorSeuil)
            {
                RebuildOperation.IndexSource = index;
                return RebuildOperation;
            }
            else
            {
                ReorganizeOperation.IndexSource = index;
                return ReorganizeOperation;
            }
        }
    }
}